from flask import session, redirect, url_for, request
from .models import *


def check_limit():
    check = request.cookies.get('username', None)
    if check:
        name = db.session.query(Admin.name).filter(Admin.password == check).scalar()
        if name:
            session['admin'] = name
    name = session.get('admin', None)
    if name is None:
        return 1
    limitnum = db.session.query(Admin.adminrank).filter(Admin.name == name).scalar()
    if limitnum != 1:
        return 2
